/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FlowWindow.java
 *
 * Created on Sep 17, 2011, 6:17:26 PM
 */

package botoseis.mainGui.temp;
import botoseis.mainGui.utils.DefaultNode;
import botoseis.mainGui.workflows.WorkflowView;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

/**
 *
 * @author gabriel
 */
public class FlowWindow extends javax.swing.JInternalFrame implements InternalFrameListener {
    private boolean open;
    /** Creates new form FlowWindow */
    public FlowWindow(String title, MainWindow mw) {
        super(title);
        initComponents();
        mainWindow = mw;
        workflowView = new WorkflowView(getParmsPanel());
        panelMain.add(workflowView);
      panelParam.removeAll();
      panelParam.updateUI();     
      m_workflowView = new botoseis.mainGui.workflows.WorkflowView(panelParam);  
      this.addInternalFrameListener(this);  

    }
// Remove !!
    private JPanel getParmsPanel() {
       return panelParam;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        panelMain = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        panelParam = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 224));
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setVisible(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameActivated(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        jSplitPane1.setDividerLocation(220);
        jSplitPane1.setDividerSize(5);

        panelMain.setLayout(new java.awt.GridLayout(1, 0));
        jScrollPane1.setViewportView(panelMain);

        jSplitPane1.setLeftComponent(jScrollPane1);

        panelParam.setBorder(javax.swing.BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red),"Parameters"));
        panelParam.setLayout(new java.awt.GridBagLayout());
        jScrollPane2.setViewportView(panelParam);

        jSplitPane1.setRightComponent(jScrollPane2);

        getContentPane().add(jSplitPane1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formInternalFrameActivated(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameActivated
        mainWindow.getFlowsPanel().getDesktopManager().activateFrame(this);
        mainWindow.setCurrentFlow(workflowView);
        panelMain.setBackground(new java.awt.Color(255, 255, 220)); 
}//GEN-LAST:event_formInternalFrameActivated


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JPanel panelMain;
    private javax.swing.JPanel panelParam;
    // End of variables declaration//GEN-END:variables
 private botoseis.mainGui.workflows.WorkflowView m_workflowView;
    private WorkflowView workflowView;
    MainWindow mainWindow;

    /**
     * @return the workflowView
     */
    public // End of variables declaration
    WorkflowView getWorkflowView() {
        return workflowView;
    }

    /**
     * @param workflowView the workflowView to set
     */
    public void setWorkflowView(WorkflowView workflowView) {
        this.workflowView = workflowView;
    }


    @Override
    public void internalFrameOpened(InternalFrameEvent e) {

    }

    @Override
    public void internalFrameClosing(InternalFrameEvent e) {
        for(DefaultNode key : mainWindow.getMapFlowWindow().keySet()){
            if(mainWindow.getMapFlowWindow().get(key).equals(this)){
                mainWindow.getMapFlowWindow().remove(key);
                setOpen(false);
            }
        }
    }

    @Override
    public void internalFrameClosed(InternalFrameEvent e) {

    }

    @Override
    public void internalFrameIconified(InternalFrameEvent e) {

    }

    @Override
    public void internalFrameDeiconified(InternalFrameEvent e) {

    }

    @Override
    public void internalFrameActivated(InternalFrameEvent e) {
    workflowView.setBackground(new java.awt.Color(255, 255, 220));
    }

    @Override
    public void internalFrameDeactivated(InternalFrameEvent e) {
        workflowView.setBackground(new java.awt.Color(229,229,229));
    }

    /**
     * @return the open
     */
    public boolean isOpen() {
        return open;
    }
    public String getTitle() {
        return m_title;
    }
        public void setTitle(String str) {
         this.m_title=str;
    }
    /**
     * @param open the open to set
     */
    public void setOpen(boolean open) {
        this.open = open;
    }
    
      private String m_title;
}
